package com.gzdh.device.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gzdh.device.comm.vo.Result;
import com.gzdh.device.system.entity.SysPermission;
import com.gzdh.device.system.model.SysPermissionTreeModel;
import com.gzdh.device.system.service.SysPermissionService;
import com.gzdh.device.system.util.FindsPermissionChildrenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/permission/v1")
public class SysPermissionController {

    @Autowired
    SysPermissionService sysPermissionService;

    /**
     * 获取菜单方式
     *
     * @return
     */
    @GetMapping("getMenuList")
    public Result<Object> getMenuList() {
        Result<Object> result = new Result<>();
        List<SysPermission> sysPermissionList = sysPermissionService.list(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::isDelFlag, false));
        List<SysPermissionTreeModel> listResult = FindsPermissionChildrenUtil.wrapTreeDataToTreeList(sysPermissionList);
        result.setResult(listResult);
        return result;
    }
}
